package com.zhihuanbao.business.sys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhihuanbao.common.annotation.Log;
import com.zhihuanbao.common.core.controller.BaseController;
import com.zhihuanbao.common.core.domain.AjaxResult;
import com.zhihuanbao.common.enums.BusinessType;
import com.zhihuanbao.business.domain.BizEnterprises;
import com.zhihuanbao.business.service.IBizEnterprisesService;
import com.zhihuanbao.common.utils.poi.ExcelUtil;
import com.zhihuanbao.common.core.page.TableDataInfo;

/**
 * 企业信息Controller
 * 
 * @author zhihuanbao
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/business/enterprises")
public class BizEnterprisesController extends BaseController
{
    @Autowired
    private IBizEnterprisesService bizEnterprisesService;

    /**
     * 查询企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:enterprises:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizEnterprises bizEnterprises)
    {
        bizEnterprises.setEnterpriseId(getEnterprisesId());
        System.out.println("当前企业："+bizEnterprises.getEnterpriseId());
        startPage();
        List<BizEnterprises> list = bizEnterprisesService.selectBizEnterprisesList(bizEnterprises);
        return getDataTable(list);
    }

    /**
     * 导出企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:enterprises:export')")
    @Log(title = "企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizEnterprises bizEnterprises)
    {
        List<BizEnterprises> list = bizEnterprisesService.selectBizEnterprisesList(bizEnterprises);
        ExcelUtil<BizEnterprises> util = new ExcelUtil<BizEnterprises>(BizEnterprises.class);
        util.exportExcel(response, list, "企业信息数据");
    }

    /**
     * 获取企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprises:query')")
    @GetMapping(value = "/{enterpriseId}")
    public AjaxResult getInfo(@PathVariable("enterpriseId") Long enterpriseId)
    {
        return success(bizEnterprisesService.selectBizEnterprisesByEnterpriseId(enterpriseId));
    }

    /**
     * 新增企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprises:add')")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizEnterprises bizEnterprises)
    {
        return toAjax(bizEnterprisesService.insertBizEnterprises(bizEnterprises));
    }

    /**
     * 修改企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprises:edit')")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizEnterprises bizEnterprises)
    {
        return toAjax(bizEnterprisesService.updateBizEnterprises(bizEnterprises));
    }

    /**
     * 删除企业信息
     */
    @PreAuthorize("@ss.hasPermi('business:enterprises:remove')")
    @Log(title = "企业信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{enterpriseIds}")
    public AjaxResult remove(@PathVariable Long[] enterpriseIds)
    {
        return toAjax(bizEnterprisesService.deleteBizEnterprisesByEnterpriseIds(enterpriseIds));
    }
}
